<template>
    <el-dialog class="edit-password" title="添加评论" append-to-body :close-on-click-modal="closeOnclickModal"
               width="500px" top="3.8vh" :visible.sync="isDialogShow" @close="close">
        <el-form :model="dialogForm" ref="dialogForm" :size="size" label-width="100px">
            <el-form-item :rules="yh_rules({required:true})" label="评论内容" prop="context">
                <el-input placeholder="请输入评论" v-model="dialogForm.context"
                          type="textarea"
                          :rows="3"
                          show-password></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="close" :size="size">取消</el-button>
            <el-button type="primary" @click="submit" :size="size">确定</el-button>
        </span>
    </el-dialog>
</template>

<script>
  import {addAppraise} from '@/api/order'
  import { mapGetters } from 'vuex'
  export default {
    name: 'DialogAppraise',
    props: {
      propInfo: {
        type: Object
      },
      dialogAppraiseShow: {
        type: Boolean,
        default: false
      },
    },
    data() {
      return {
        dialogForm: {
          context: ''
        },
        isDialogShow: false
      }
    },
    computed: {
      ...mapGetters(['login_user'])
    },
    watch: {
      dialogAppraiseShow (newValue) {
        this.isDialogShow = newValue
      }
    },
    methods: {
      submit() {
        this.$refs.dialogForm.validate(valid => {
          if (valid) {
            this.addAppraise()
          }
        })
      },
      addAppraise() {
        let params = {
          context: this.dialogForm.context,
          infoId: this.propInfo.infoId,
          orderId: this.propInfo.orderId,
          parentId: ''
        }
        addAppraise(params).then(res => {
          this.$message.success('添加成功')
          this.close()
        })
      },
      close () {
        this.dialogForm = {
          context: ''
        }
        this.$emit('update:dialogAppraiseShow', false)
      },
    }
  }
</script>
